package alg.list;

/**
 * @author:yuziji
 * @create: 2023-04-26 15:16
 * 查找链表的中间节点
 */
public class MiddleNode {
    public static void main(String[] args) {
        Node head = new Node(1);
        head.next = new Node(2);
        head.next.next = new Node(3);
        System.out.println(middleNode(head).value);

    }

    private static Node middleNode(Node head){
        Node fast = head;
        Node slow = head;
        while(fast!=null&&fast.next!=null){
            fast = fast.next.next;
            slow = slow.next;
        }
        return slow;
    }
}
